package org.hot100.h104;

/**
 * @Author: wjy
 * @Date: 2021/12/30 9:01
 */
public class Solution {

    /**
     * 给定一个二叉树，找出其最大深度。
     *
     * 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
     *
     * 说明: 叶子节点是指没有子节点的节点。
     *
     * 示例：
     *
     * 给定二叉树 [3,9,20,null,null,15,7]，返回它的最大深度 3 。
     *
     * @param args
     */
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(3);
        TreeNode treeNode2 = new TreeNode(4);
        TreeNode treeNode3 = new TreeNode(2, treeNode1, treeNode2);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(3);
        TreeNode treeNode6 = new TreeNode(3, treeNode4, treeNode5);
        TreeNode treeNode7 = new TreeNode(1, treeNode3, treeNode6);

        Solution solution = new Solution();
        System.out.println(solution.maxDepth(treeNode7));

    }

    public int maxDepth(TreeNode root) {

        return root == null ? 0 : Math.max(this.maxDepth(root.left), this.maxDepth(root.right)) + 1;

    }
    
}
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}